package srzy.driver

import srzy.common.Logging
import srzy.dao.DBUtil
import srzy.common.Common
import spray.json._
import DefaultJsonProtocol._
import srzy.common.Config
import java.io.File
import srzy.socket.DCCSocketConn

object Startc extends Logging {

  val dbSource = DBUtil("CaseInfoSource")

  def deal1 = {
    logger.debug("begin read json file")
    val caseInfos = srzy.common.Common.readFromFile("data.json", "UTF-8").mkString("\n").asJson.convertTo[scala.collection.immutable.Map[String, (String, String, String, String)]]
    logger.debug("read json file over")
    Common.readFromFile("etc" + java.io.File.separator + "refresh.txt").filter(x => if (x == "") false else true).foreach(path => {
      logger.debug("case :" + path)
      val f = new File(path)
      if (!f.isFile())
        throw new Exception(path + "并不是一个文件")
      val caseName = f.getName()
      caseInfos.get(caseName) match {
        case Some(v) =>
          dbSource.updateCaseInfo(caseName, v._1, v._2, v._3, v._4)
          logger.debug("update case " + caseName + " over")
        case None => logger.error("not contain case " + caseName)
      }
    })
  }

  def deal2 = {
    println(DCCSocketConn.ASAMsg("111"))
  }

  def deal = { deal1 }

  def main(args: Array[String]): Unit = { deal }
}